import java.io.*;
import java.net.*;
import java.lang.String;
import java.util.ArrayList;

public class ClientTest {

    public static void main(String[] pArgs) 
    {
        if(pArgs.length<3)
        {
            //System.out.println("usage: java Client host port boardnum");
            return;
        }

        try
        {
            Socket lSocket = new Socket(pArgs[0],Integer.parseInt(pArgs[1]));
            PrintWriter lOut = new PrintWriter(lSocket.getOutputStream());
            BufferedReader lIn = new BufferedReader(new InputStreamReader(
                                                   lSocket.getInputStream()));

            lOut.println(pArgs[2]);
            lOut.flush();

            String lLine = lIn.readLine();
            ArrayList<String> lines = new ArrayList<String>();

            //System.out.println("Line received: " + lLine);
            //Read number of rows
            int lNumRows = Integer.parseInt(lLine);

            //Read each row
            for(int i = 0; i < lNumRows; ++ i)
            {
            	lLine = lIn.readLine();            	
                lines.add(lLine);
            }

            // Build the board.
//            lines = easyBoard1();
            
	        Board board = new Board(lines);
//	        System.out.println(board.toString());
            
	        //Put your board Test things here
	        //Test of static tunnel detection initialization
	        System.out.println(board.toString());
	        //board.computeTunnels();
	        
            // Solve the board!
//            LinkedList<Position> boxes = new LinkedList<Position>();
//            boxes.addAll(board.getBoxes()); 
//
//            dp = new LinkedList<BoardListPair>();
//            GregorianCalendar st = new GregorianCalendar();
//            String boxPath = findSolution(board);
//            System.out.println("Time to find solution: " + ((new GregorianCalendar()).getTimeInMillis() - st.getTimeInMillis()) + "msecs");
//
////            System.out.println(board.toString());
////            System.out.println("Path to get there: " + boxPath);
//
////            (new SolutionChecker()).recreateSolution(board, boxPath);
//
            //Send the solution to the server
            lOut.println("");
            lOut.flush();

            //Read answer from the server
            lLine = lIn.readLine();

            System.out.println(lLine);
        }
        catch(Throwable t)
        {
            t.printStackTrace();
        }
    }

}
